module.exports = (app) => {
  const { Schema, model, getModelName, pre } = app.jax.mongoose
  const modelName = getModelName(__filename)

  const adminDepartmentSchema = new Schema({
    systemType: String, // 所属系统(请看字典)
    parentId: Schema.Types.ObjectId, // 上级ID
    departmentName: String, // 部门名称
    remark: String, // 备注
  })

  // 修改
  adminDepartmentSchema.pre(['updateOne', 'findOneAndUpdate', 'updateMany'], function () {
    const data = this.getUpdate()
    pre.getRank(data)
  })

  // 新增
  adminDepartmentSchema.pre('save', function () {
    pre.getRank(this)
  })

  const AdminDepartmentSchema = model(modelName, adminDepartmentSchema, null, null, {
    id: 'departmentId',
  })

  return AdminDepartmentSchema
}
